<template>
  <div class="box">
    <div class="middle">
      <img src="../assets/sign.png" alt="">
      <div class="div1">核验授权</div>
      <br>
      <div class="div2">输入您的钱包地址以及您购买的版权文件哈希即可验证您是否拥有授权</div>
      <br>
      <div class="div3">
        <strong>文件哈希</strong>
        <br>
        <input type="text" placeholder="请输入文件哈希" v-model="fileHash">
        <br>
        <strong>钱包地址</strong>
        <br>
        <input type="text" placeholder="请输入钱包地址" v-model="walletAddress">
        <br>
        <button @click="search">查询</button>
      </div>
    </div>
  </div>

</template>

<script>

// eslint-disable-next-line no-unused-vars
import confluxPortal from "@/conflux/conflux-portal";
import {ElMessage} from "element-plus";
// eslint-disable-next-line no-unused-vars
import {ContractCopyright, ContractHnuCoin} from "@/conflux/conflux";
// eslint-disable-next-line no-unused-vars
import {Drip} from "js-conflux-sdk";

export default {
  name: 'VerificateOnChain3',
  data() {
    return {
      account:'',
      fileHash:'',
      walletAddress:'',
    }
  },
  methods:{
    async search() {
      try {
        const isProve=await ContractCopyright.contract.isDownload(
            this.fileHash,
            this.walletAddress
        )
        if(isProve==true){
          ElMessage({
            message:'已授权',
            type:'success'
          })
        }else {
          ElMessage({
            message:'未授权',
            type:'error'
          })
        }
      }catch (e){
        ElMessage({
          message:'无结果',
          type:'error'
        })
      }
      /*
      await confluxPortal.enable();
      this.account = confluxPortal.getAccount();
      if (this.account == '') {
        ElMessage({
          message: '您还未连接conflux钱包插件',
          type: 'warning'
        });
      } else {
        console.log(this.account);
        try {
          //转账
          const transCalled = ContractHnuCoin.contract.transfer(
              this.account,
              'net1024:aajbt7xmns44ke7c294ad1byfjdjv62vp28drjy0j4',
              Drip.fromCFX(5).toString()
          )
          console.log(transCalled);
          const transaction1 = await confluxPortal.sendTransaction({
            from: this.account,
            to: transCalled.to,
            data: transCalled.data,
          })
          const txHash1 = transaction1.result;
          console.log(txHash1)
          //授权
          const called= ContractCopyright.contract.downloadWorks(
              'net1024:aajbt7xmns44ke7c294ad1byfjdjv62vp28drjy0j4',
              '8369D29444E818AE1E4D39D194857C22',
              '邓磊',
              '123456'
          )
          console.log(called)
          const transaction = await confluxPortal.sendTransaction({
            from: this.account,
            to: called.to,
            data: called.data,
          })
          const txHash2 = transaction.result;
          console.log(txHash2)
        } catch (e) {
          ElMessage({
            message: "查询失败",
            type: "error"
          });
        }
      }*/
    }
  }
}
</script>

<style scoped>
.box {
  border: 0px;
  margin: 50px auto;
  height: 700px;
  width: 1600px;
  border-radius: 20px;
}

img {
  float: left;
  width: 30px;
  margin-left: 50px;
}

.middle .div1 {
  float: left;
  margin-left: 20px;
  margin-top: 5px;
}

.middle .div2 {
  margin-left: 100px;
  margin-top: 20px;
  color: gray;
}

.middle .div3 {
  margin-left: 100px;
  margin-top: 60px;
}

.div3 input {
  margin: 10px 0;
  width: 800px;
}

.elTable {
  margin-left: 100px;
  margin-top: 30px;
  width: 600px;

}
</style>
